﻿using System;

class TwistedOrder
{
    //this isn't the method you're looking for
    //Please look at 33 lines below
    static ConsoleColor GetRandomColor(int action)
    {
        ConsoleColor color = new ConsoleColor();
        switch (action)
        {
            case 1:
                color = ConsoleColor.Blue;
                break;
            case 2:
                color = ConsoleColor.Red;
                break;
            case 3:
                color = ConsoleColor.Green;
                break;
            case 4:
                color = ConsoleColor.Yellow;
                break;
            case 5:
                color = ConsoleColor.Magenta;
                break;
            case 6:
                color = ConsoleColor.DarkRed;
                break;
            default:
                color = ConsoleColor.White;
                break;
        }
        return color;
    }

    static void Main()
    {

        int counter = 1;
        int coll = 0;
        int row = 0;
        Random random = new Random();
        Console.ForegroundColor = GetRandomColor(random.Next(1, 6));
        Console.WriteLine("14. Write a program that reads a positive \ninteger number N (N < 20) from console and \noutputs in the console the numbers \n1 ... N numbers arranged as a spiral.\n");
        Console.ForegroundColor = ConsoleColor.White;
        Console.Write("Enter a positive integer number N (N < 20)");
        

        int number = int.Parse(Console.ReadLine());
        int[,] matrix = new int[number, number];
        for (int i = 0; i < number; i++)
        {
            row = 0 + i;
            //Moving right
            for (coll = 0 + i; coll <= (number - 1 - i); coll++)
            {
                matrix[row, coll] = counter;
                counter++;
            }

            //Decreasing number of columns
            coll--;

            //Moving down
            for (row = 1 + i; row <= number - 1 - i; row++)
            {
                matrix[row, coll] = counter;
                counter++;

            }
            //Decreasing number of columns and rows
            row--;
            coll--;

            //Moving left
            for (coll = number - 2 - i; coll >= i; coll--)
            {

                matrix[row, coll] = counter;
                counter++;
            }
            //Decreasing column from right side
            coll++;

            // Moving up
            for (row = number - 2 - i; row > i; row--)
            {
                matrix[row, coll] = counter;
                counter++;

            }

        }
        Console.WriteLine("\n\n");
        //Printing matrix
        //I hope you like it
        //More colors = more fun :):)

        for (int i = 0; i < number; i++)
        {
            for (int j = 0; j < number; j++)
            {
                Console.ForegroundColor = GetRandomColor(random.Next(1, 6));
                Console.Write("{0}\t", matrix[i, j]);

            }
            Console.WriteLine("\n");
        }


    }
}



